/*    
    OpenMheg - A free MHEG-5 library
    Copyright (C) 2008 Dharmesh Malam

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Text;
using Core.Model.Actions;

namespace Core.Model.Events
{
    public enum enumEvents
    {
        AnchorFired,
        AsynchStopped,
        BooleanDataEvent,
        ContentAvailable,
        CounterTrigger,
        CursorEnter,
        CursorLeave,
        EngineEvent,
        EntryFieldFull,
        Event,
        FirstItemPresented,
        HeadItems,
        HighlightOff,
        HighlightOn,
        IntegerDataEvent,
        InteractionCompleted,
        IsAvailable,
        IsDeleted,
        IsDeselected,
        IsRunning,
        IsSelected,
        IsStopped,
        ItemDeselected,
        ItemSelected,
        LastItemPresented,
        OctetStringDataEvent,
        StreamEvent,
        StreamPlaying,
        StreamStopped,
        TailItems,
        TestEvent,
        TimerFired,
        TokenMovedFrom,
        TokenMovedTo,
        UserInput,
        Unknown
    }

    public abstract class Event
    {
        private Root source;
        protected bool synchronous = true;
        internal enumEvents type;
        
        public static string GetEventName ( int type )
        {
            string ret = "Unknown";

            switch ( type )
            {
                case 1:
                    ret = "IsAvailable";
                    break;
                case 2:
                    ret = "ContentAvailable";
                    break;
                case 3:
                    ret = "IsDeleted";
                    break;
                case 4:
                    ret = "IsRunning";
                    break;
                case 5:
                    ret = "IsStopped";
                    break;
                case 6:
                    ret = "UserInput";
                    break;
                case 7:
                    ret = "AnchorFired";
                    break;
                case 8:
                    ret = "TimerFired";
                    break;
                case 9:
                    ret = "AsynchStopped";
                    break;
                case 10:
                    ret = "InteractionCompleted";
                    break;
                case 11:
                    ret = "TokenMovedFrom";
                    break;
                case 12:
                    ret = "TokenMovedTo";
                    break;
                case 13:
                    ret = "StreamEvent";
                    break;
                case 14:
                    ret = "StreamPlaying";
                    break;
                case 15:
                    ret = "StreamStopped";
                    break;
                case 16:
                    ret = "CounterTrigger";
                    break;
                case 17:
                    ret = "HighlightOn";
                    break;
                case 18:
                    ret = "HighlightOff";
                    break;
                case 19:
                    ret = "CursorEnter";
                    break;
                case 20:
                    ret = "CursorLeave";
                    break;
                case 21:
                    ret = "IsSelected";
                    break;
                case 22:
                    ret = "IsDeselected";
                    break;
                case 23:
                    ret = "TestEvent";
                    break;
                case 24:
                    ret = "FirstItemPresented";
                    break;
                case 25:
                    ret = "LastItemPresented";
                    break;
                case 26:
                    ret = "HeadItems";
                    break;
                case 27:
                    ret = "TailItems";
                    break;
                case 28:
                    ret = "ItemSelected";
                    break;
                case 29:
                    ret = "ItemDeselected";
                    break;
                case 30:
                    ret = "EntryFieldFull";
                    break;
                case 31:
                    ret = "EngineEvent";
                    break;
            }

            return ret;
        }

        public static enumEvents getEvent ( int type )
        {
            enumEvents ret = enumEvents.Unknown;

            switch ( type )
            {
                case 1:
                    ret = enumEvents.IsAvailable;
                    break;
                case 2:
                    ret = enumEvents.ContentAvailable;
                    break;
                case 3:
                    ret = enumEvents.IsDeleted;
                    break;
                case 4:
                    ret = enumEvents.IsRunning;
                    break;
                case 5:
                    ret = enumEvents.IsStopped;
                    break;
                case 6:
                    ret = enumEvents.UserInput;
                    break;
                case 7:
                    ret = enumEvents.AnchorFired;
                    break;
                case 8:
                    ret = enumEvents.TimerFired;
                    break;
                case 9:
                    ret = enumEvents.AsynchStopped;
                    break;
                case 10:
                    ret = enumEvents.InteractionCompleted;
                    break;
                case 11:
                    ret = enumEvents.TokenMovedFrom;
                    break;
                case 12:
                    ret = enumEvents.TokenMovedTo;
                    break;
                case 13:
                    ret = enumEvents.StreamEvent;
                    break;
                case 14:
                    ret = enumEvents.StreamPlaying;
                    break;
                case 15:
                    ret = enumEvents.StreamStopped;
                    break;
                case 16:
                    ret = enumEvents.CounterTrigger;
                    break;
                case 17:
                    ret = enumEvents.HighlightOn;
                    break;
                case 18:
                    ret = enumEvents.HighlightOff;
                    break;
                case 19:
                    ret = enumEvents.CursorEnter;
                    break;
                case 20:
                    ret = enumEvents.CursorLeave;
                    break;
                case 21:
                    ret = enumEvents.IsSelected;
                    break;
                case 22:
                    ret = enumEvents.IsDeselected;
                    break;
                case 23:
                    ret = enumEvents.TestEvent;
                    break;
                case 24:
                    ret = enumEvents.FirstItemPresented;
                    break;
                case 25:
                    ret = enumEvents.LastItemPresented;
                    break;
                case 26:
                    ret = enumEvents.HeadItems;
                    break;
                case 27:
                    ret = enumEvents.TailItems;
                    break;
                case 28:
                    ret = enumEvents.ItemSelected;
                    break;
                case 29:
                    ret = enumEvents.ItemDeselected;
                    break;
                case 30:
                    ret = enumEvents.EntryFieldFull;
                    break;
                case 31:
                    ret = enumEvents.EngineEvent;
                    break;
            }

            return ret;
        }
        
        public Event ( Root source )
        {
            this.source = source;
        }

        public Root Source 
        {
            get{return source;}
        }

        public bool IsSynchronous 
        {
            get{return synchronous;}
        }

        public enumEvents Type 
        {
            get{return type;}
         
        }

        public String getEventName ()
        {
            String name =  GetType().ToString();
            int i;

            if ( ( i = name.LastIndexOf( '.' ) ) != -1 )
                name = name.Substring( ++i );

            return name;
        }

        public override string ToString ()
        {
            return (synchronous ? "Synchronous ":"Asynchronous ") +  getEventName() + " sourced " + source;
        }

  
    }
}
